<?php

namespace App\Models\Fee;

use App\Models\Asset;
use App\Models\AssetStock;
use Hyn\Tenancy\Traits\UsesTenantConnection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * App\Models\Fee\FeeFormula
 *
 * @property int $id
 * @property string $name
 * @property string|null $description
 * @property string $criteria 规则
 * @property string $formula 对应的计算公式
 * @property \Illuminate\Support\Carbon|null $deleted_at
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @method static bool|null forceDelete()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Fee\FeeFormula fuzzyFilter($queryString)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Fee\FeeFormula newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Fee\FeeFormula newQuery()
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Fee\FeeFormula onlyTrashed()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Fee\FeeFormula query()
 * @method static bool|null restore()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Fee\FeeFormula whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Fee\FeeFormula whereCriteria($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Fee\FeeFormula whereDeletedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Fee\FeeFormula whereDescription($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Fee\FeeFormula whereFormula($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Fee\FeeFormula whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Fee\FeeFormula whereName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Fee\FeeFormula whereUpdatedAt($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Fee\FeeFormula withTrashed()
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Fee\FeeFormula withoutTrashed()
 * @mixin \Eloquent
 */
class FeeFormula extends Model
{
    use SoftDeletes, UsesTenantConnection;
    protected $guarded = [];
    const ASSET_TYPE_ASSET = Asset::class;
    const ASSET_TYPE_ASSET_STOCK = AssetStock::class;
    // 可选的类别规则为[name， ]

    const TYPE = [
        "name" => "名称",
        "category_id" => "一级分类",
        "sub_category_id" => "二级分类",
        "operator" => "操作",
        "price" => "价格",
    ];

    public function scopeFuzzyFilter($query, $queryString)
    {
        $likeStr = '%' . $queryString . '%';
        $query->where('name', 'like', $likeStr);
        return $query;
    }

}
